#! /usr/bin/env python
# -*- coding: utf-8 -*-
from functools import wraps
import flask
from flask_login import current_user

from app.models import Permission


def permission_required(permission):
    def decorator(func):
        @wraps(func)
        def decorated_functions(*args, **kwargs):
            if not current_user.can(permission):
                flask.abort(403)
            return func(*args, **kwargs)
        return decorated_functions
    return decorator


def admin_required(func):
    return permission_required(Permission.ADMIN)(func)
